package asia.lxq.cic.entity;

import asia.lxq.cic.dao.UserMapper;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@TableName("organization")
public class Group {
    @TableId(value = "group_id",type = IdType.AUTO)
    private Long groupId;
    private String groupName;
    private int groupLeaderId;
    private int groupCollegeId;
    @TableField(exist = false)
    private User leader;
    @TableField(exist = false)
    private List<User> studentList;
    @TableField(exist = false)
    private int groupCount;

    public void query(UserMapper userMapper, boolean getStudentList){
        if (getStudentList){
            QueryWrapper<User> queryWrapper=new QueryWrapper<>();
            queryWrapper.like("belong","%,%,"+groupCollegeId+","+groupId);
            studentList=userMapper.selectList(queryWrapper);
            if (studentList!=null)groupCount=studentList.size();
        }
        leader=userMapper.selectById(groupLeaderId);
    }
}
